package com.multi.thread.chapter04.demo08;

import java.util.concurrent.locks.ReentrantLock;

/**
 *	getHoldCount() 查询当前线程保持此锁定的个数
 */
public class TestHoldCount {
	
	private ReentrantLock lock = new ReentrantLock();
	
	public void serviceMethod01() {
		try {
			lock.lock();
			System.out.println("serviceMethod01 getHoldCount = " + lock.getHoldCount());
			serviceMethod02();
		} finally {
			lock.unlock();
		}
	}
	
	public void serviceMethod02() {
		try {
			lock.lock();
			System.out.println("serviceMethod02 getHoldCount = " + lock.getHoldCount());
		} finally {
			lock.unlock();
		}
	}
	
	public static void main(String[] args) {
		TestHoldCount service = new TestHoldCount();
		service.serviceMethod01();
	}

}
